LassoScript Utility
Basics Browse Detail

[Net->Accept]

Tag Link [Net->Accept] Category Networking
Type Member Source Available Yes
Support Preferred Version 7.0
Change Unchanged Data Source Any
Output Type None Security None
Implementation LCAPI Sets Lasso 8.5, Lasso 8.0, Lasso 7.0

Description

[Net->Accept] is used with TCP listeners to accept an incoming connection. The tag returns a new [Net] object that represents the connection with the remote server that initiated the request. [Net->Accept] will wait forever for an incoming connection. [Net->Accept] can be used multiple times to accept requests from many different remote servers using the same listener.

In order to prepare a [Net] object as a listener the [Net->SetType] tag must be called with [Net_TypeTCP], the object must be bound to a port using [Net->Bind] and the object must be put into listening mode using [Net->Listen].

Syntax

<?LassoScript
Variable: 'Listener' = (Net);
$Listener->(Bind: 8000);
$Listener->(Listen);
Variable: 'Connection' = $Listener->Accept;
...
$Connection->Close;
$Listener->Close;
?>

Parameters

No Parameters Required.

Examples

To listen for incoming TCP connections:

Use the [Net] type and its member tags to establish a TCP listener. The following example listens on port 80 for incoming TCP traffic. The [Net->Accept] tag returns a new connection and the IP address of the local machine and the remote machine are reported.

[Variable: 'myListener' = (Net)]
[$myListener->(Bind: 80)]
[$myListener->(Listen)]
[Variable: 'myConnecton' = $myListener->(Accept)]
Local: [Output: $myConnection->(LocalAddress)]
Remote: [Output: $myConnection->(RemoteAddress)]
[Variable: 'Input' = $myConnection->(Read: 32768)]
...
[$myConnection->(Close)]
[$myListener->(Close)]

Local: 127.0.0.1
Remote: www.example.com